unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, GLScene, GLObjects, GLCoordinates, GLWin32Viewer,
  GLCrossPlatform, BaseClasses, GLKeyboard, GLCadencer, GLNavigator, GLSmoothNavigator,
  StdCtrls, ExtCtrls, inifiles,
  GameClasses, LuaEngine, SectorLoader, Engine,
  GLVectorFileObjects, AsyncTimer, GLMaterial;
type
  TForm1 = class(TForm)
    GLSceneViewer1: TGLSceneViewer;
    Button1: TButton;
    log: TMemo;
    Button2: TButton;
    AsyncTimer1: TAsyncTimer;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure AsyncTimer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;
  Engine: TGEngine;
  MainIni: TIniFile;
  Test1: TGStar;
  LuaEngine_1: TGLuaEngine;
  TestPl: TGPlayer;
  TestTrigger: TGTrigger;
  TestStation: TGNPC;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
x,y: integer;

begin
Engine:=TGEngine.Create(Form1);
Engine.LoadSector('Sector_1-1.cfg');
GLSceneViewer1.Camera:=Engine.Camera;
AsyncTimer1.Enabled:=true;
log.Lines.Add('Engine started');
{
//Lua Engine start
  try
    LuaEngine_1:=TGLuaEngine.Create(Engine);
    log.Lines.Add('Lua engine started');
  except
    //
    log.Lines.Add('error: Lua isnt started');
  end;
}
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
//if not (LuaEngine_1.luaExec('Lua/test.lua')=true) then log.Lines.Add('error: Lua script invalid')
//                                            else log.Lines.Add('Lua script executed');
Engine.Lua.luaExec('Lua/test.lua');
end;

procedure TForm1.AsyncTimer1Timer(Sender: TObject);
begin

GLSceneViewer1.Invalidate;
log.Lines.Add('Current POS: '+ floattostr(trunc(Engine.Player.GetPosX))+' ' + floattostr(trunc(Engine.Player.GetPosZ)));
//if TestTrigger.progress(GLCadencer1)=true then log.Lines.Add('Ship in trigger zone!');

end;

end.
